(function(app){
	app
		.controller("content_23_inputCtrl",["$scope","$state","myFactory",'$stateParams',"$q",'$timeout','$location','$http','$ionicHistory',function($scope,$state,myFactory,$stateParams,$q,$timeout,$location,$http,$ionicHistory){

			//接收参数
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var product="";
			var token=sessionStorage.getItem("token");
			
			$scope.chdrnum01=$stateParams.chdrnum01; //保单号
			$scope.show23bbjFlag = false;//默认不显示不补缴欠缴保险费
			$scope.showBjqjbxfFlag = false;
			var isAdd="";
			$scope.data = {
				radioFlag: true
			};

/**********************************************初始化函数begin****************************************************/
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						$scope.chdrnum01=response.data.data.policy.base.chdrnum01;
						product=response.data.data.modelMap.product;
	
						console.log("product:"+product);
						//product='1';
						if(product=='2'){
							isAdd="O";
							$scope.showBjqjbxfFlag = false;
						}else{
							$scope.showBjqjbxfFlag = true;
							if(product=='1'){
								$scope.show23bbjFlag = true;//显示投保人界面
							}
						}
						initFlag=true;//标识初始化成功
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
/**********************************************初始化函数end****************************************************/
			$scope.isLabeType = function(type){
				if(type=='1'){//补缴欠缴保险费
					$scope.data.radioFlag = true;
				}else{
					$scope.data.radioFlag = false;
				}
				console.log("data.radioFlag:"+$scope.data.radioFlag);
			}


			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//返回上一页
			$scope.goBack = function(){
				myFactory.goBack();
			}

            //下一步
			$scope.nextStep = function(){
				//判断是否初始化完成了，如果失败，不予进入下一步
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return;
				}
				var sourceFlag = $("#sourceFlag").val();
				
				if($scope.showBjqjbxfFlag){
					var isAddFlag=$scope.data.radioFlag;
					isAdd="Y";
					if(!isAddFlag){
						isAdd="N";
					}
				}

				var item23={"isAdd":isAdd,"sourceFlag":sourceFlag};
				$ionicHistory.clearCache().then(function(){
					$state.go('content_23_common',{
						itemId:itemId,chdrnum01:chdrnum01,chdrcoy:chdrcoy,item23:item23
					});
				})
			}

			//保单详情
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn23Input','policyWindowOn23Input','policyCloseXOn23Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化查询订单详情
				var policyData;
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}

			//保单详情弹窗关闭
			$scope.policyCancelOn23Input = function(){
				modal('close','policyModalOn23Input','policyWindowOn23Input','policyCloseXOn23Input');
			}

			//关闭遮罩
			$scope.overwindowClose = function(){
				//$(".overwindow").show();
				$(".overwindow").hide();
				$(".overmodal").hide();
			}
			
		}]);

	    //指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});

})(app)